package com.chuangke.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.admin.service.SysRoleDeptService;
import com.chuangke.common.http.HttpResult;

/**
 * 角色权限控制器
 * 
 * @author chuangke
 * @date Oct 29, 2018
 */
@RestController
@RequestMapping("roledept")
public class SysRoleDeptController {

	@Autowired
	private SysRoleDeptService sysRoleDeptService;
	
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/saveDataRule")
	public HttpResult saveDataRule(@RequestParam String roleId,@RequestParam String dataRule,@RequestParam List<String> deptIds) {
		sysRoleDeptService.saveDataRule(roleId,dataRule,deptIds);
		return HttpResult.ok();
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/removeDataRule")
	public HttpResult removeDataRule(@RequestParam String roleId) {
		sysRoleDeptService.removeDataRule(roleId);
		return HttpResult.ok();
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/saveAuditRule")
	public HttpResult saveAuditRule(@RequestParam String roleId,@RequestParam String auditRule,@RequestParam List<String> deptIds) {
		sysRoleDeptService.saveAuditRule(roleId,auditRule,deptIds);
		return HttpResult.ok();
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/removeAuditRule")
	public HttpResult removeAuditRule(@RequestParam String roleId) {
		sysRoleDeptService.removeAuditRule(roleId);
		return HttpResult.ok();
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/synUserInheritRole")
	public HttpResult synUserInheritRole(@RequestParam String userId) {
		sysRoleDeptService.synUserInheritRole(userId);
		return HttpResult.ok();
	}
	

}
